package com.jing.weibo.controller.pb;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jing.system.comm.BaseController;
import com.jing.weibo.pojo.pb.PbType;
import com.jing.weibo.pojo.pb.PbTypeSeat;
import com.jing.weibo.pojo.user.UserInfo;
import com.jing.weibo.service.pb.PbTypeSeatService;
import com.jing.weibo.service.pb.PbTypeService;

/**
 * 泡吧分区位置的Controller
 * @author jing.yue
 * @version 2012/09/29 1.0.0
 */
@Controller
public class PbTypeSeatController extends BaseController {

	private static final Logger logger = Logger.getLogger(PbTypeSeatController.class);

	@Autowired
	private PbTypeService pbTypeService;
	@Autowired
	private PbTypeSeatService pbTypeSeatService;

	/**
	 * 添加泡吧分区位置
	 * @return
	 */
	@RequestMapping(value = "/pbTypeSeat/json/addPbTypeSeat")
	@ResponseBody
	public ModelMap addPbType(HttpServletRequest request, PbTypeSeat pbTypeSeat) {
		String result = null;
		UserInfo userInfo = getSessionUser(request);
		//不为管理员
		if(userInfo.getIsadmin().intValue() != 1) {
			logger.error(userInfo.getNickname() + ": 您不是管理员!");
			result = ERROR_NOT_ADMIN;
		}
		else {
			try {
				pbTypeSeat.setAdduser(userInfo.getUsername());
				pbTypeSeatService.savePbTypeSeat(pbTypeSeat);
				result = SUCCESS;
			} catch (Exception e) {
				logger.error(userInfo.getNickname() + ": 添加泡吧分区位置异常!", e);
				result = ERROR;
			}
		}
		ModelMap modelMap = new ModelMap();
		modelMap.put("result", result);
		return modelMap;
	}

	/**
	 * 跳转到泡吧分区位置管理页面
	 * @param request
	 * @return
	 */
	@RequestMapping("/toPbTypeSeatManager")
	public String toPbTypeManager(HttpServletRequest request, ModelMap modelMap) {
		UserInfo userInfo = getSessionUser(request);
		//不为管理员
		if(userInfo.getIsadmin().intValue() != 1) {
			logger.error(userInfo.getNickname() + ": 您不是管理员!");
			return ERROR_ADMIN;
		}
		try {
			//获取泡吧分区
			List<PbType> pbTypeList = pbTypeService.findAllPbType();
			modelMap.put("pbTypeList", pbTypeList);
		} catch (Exception e) {
			logger.error("获取泡吧分区异常!", e);
		}
		return "admin/pb/pbtypeseat_manager";
	}

	/**
	 * 获取泡吧分区位置列表
	 * @return
	 */
	@RequestMapping(value = "/pbTypeSeat/json/findPbTypeSeat")
	@ResponseBody
	public ModelMap findPbTypeSeat(HttpServletRequest request, PbTypeSeat pbTypeSeat) {
		String result = null;
		String weiboMsg = null;
		Map<String, Object> map = null;
		UserInfo userInfo = getSessionUser(request);
		try {
			map = pbTypeSeatService.findPbTypeSeat(pbTypeSeat);
			result = SUCCESS;
		} catch (Exception e) {
			logger.error(userInfo.getNickname() + ": 获取获取泡吧分区位置列表异常!", e);
			result = ERROR;
		}
		ModelMap modelMap = new ModelMap();
		modelMap.put("data", map);
		modelMap.put("result", result);
		modelMap.put("weiboMsg", weiboMsg);
		return modelMap;
	}

	/**
	 * 根据用户获取推荐泡吧分区位置的信息
	 * @return
	 */
	/*@RequestMapping(value = "/pbTypeSeat/json/findUserSeatRecommend")
	@ResponseBody
	public ModelMap findUserSeatRecommend(HttpServletRequest request, PbTypeSeat pbTypeSeat) {
		String result = null;
		String weiboMsg = null;
		Map<String, Object> map = null;
		UserInfo userInfo = getSessionUser(request);
		try {
			map = pbTypeSeatService.findPbTypeSeat(pbTypeSeat);
			result = SUCCESS;
		} catch (Exception e) {
			logger.error(userInfo.getNickname() + ": 根据用户获取推荐泡吧分区位置的信息异常!", e);
			result = ERROR;
		}
		ModelMap modelMap = new ModelMap();
		modelMap.put("data", map);
		modelMap.put("result", result);
		modelMap.put("weiboMsg", weiboMsg);
		return modelMap;
	}*/
}